{% extends "base_tabler.html" %} {% block title %}添加用户{% endblock %} {% block content %}
<div class="page-header d-print-none">
  <div class="container-xl">
    <div class="row g-2 align-items-center">
      <div class="col">
        <h2 class="page-title">添加用户</h2>
      </div>
      <div class="col-auto ms-auto d-print-none">
        <div class="btn-list">
          <a href="{% url 'user_manage' %}" class="btn btn-outline-secondary d-none d-sm-inline-block">
            <svg
              xmlns="http://www.w3.org/2000/svg"
              class="icon icon-tabler icon-tabler-arrow-left"
              width="24"
              height="24"
              viewBox="0 0 24 24"
              stroke-width="2"
              stroke="currentColor"
              fill="none"
              stroke-linecap="round"
              stroke-linejoin="round"
            >
              <path stroke="none" d="M0 0h24v24H0z" fill="none" />
              <path d="M5 12l14 0" />
              <path d="M5 12l6 6" />
              <path d="M5 12l6 -6" />
            </svg>
            返回用户管理
          </a>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="page-body">
  <div class="container-xl">
    <div class="row row-cards">
      <div class="col-12">
        <form class="card" method="post" action="{% url 'add_user' %}">
          {% csrf_token %}
          <div class="card-header">
            <h3 class="card-title">用户信息</h3>
          </div>
          <div class="card-body">
            {% if messages %}
            <div class="alert alert-danger" role="alert">{% for message in messages %} {{ message }} {% endfor %}</div>
            {% endif %}

            <div class="mb-3">
              <label class="form-label required">用户名</label>
              <input type="text" class="form-control" name="username" placeholder="请输入用户名" required />
              <small class="form-hint">唯一标识符，最多150个字符。仅可使用字母、数字和 @/./+/-/_ 字符。</small>
            </div>

            <div class="mb-3">
              <label class="form-label">邮箱</label>
              <input type="email" class="form-control" name="email" placeholder="user@example.com" />
            </div>

            <div class="mb-3">
              <label class="form-label required">密码</label>
              <input type="password" class="form-control" name="password" placeholder="请输入密码" required />
              <small class="form-hint"
                >密码要求：至少6个字符；不能与用户名太相似；不能是常见密码。也可以使用6位数字作为密码。</small
              >
            </div>

            <div class="mb-3">
              <div class="form-label">权限</div>
              <div>
                <label class="form-check form-check-inline">
                  <input class="form-check-input" type="checkbox" name="is_staff" />
                  <span class="form-check-label">管理员权限 (is_staff)</span>
                </label>
                <label class="form-check form-check-inline">
                  <input class="form-check-input" type="checkbox" name="is_superuser" />
                  <span class="form-check-label">超级管理员 (is_superuser)</span>
                </label>
              </div>
            </div>

            <div class="mb-3">
              <label class="form-label">角色</label>
              <select class="form-select" name="groups" multiple>
                {% for group in groups %}
                <option value="{{ group.id }}">{{ group.name }}</option>
                {% endfor %}
              </select>
              <small class="form-hint">按住 Ctrl 键（在Mac上是 Command 键）可以选择多个角色。</small>
            </div>
          </div>
          <div class="card-footer text-end">
            <button type="submit" class="btn btn-primary">创建用户</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}
